package zhibi.wechat.mp.controller;

import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import zhibi.frame.domain.Page;
import zhibi.frame.mybatis.example.Example;
import zhibi.frame.mybatis.example.ExampleType;
import zhibi.wechat.mp.extra.base.BaseController;
import zhibi.wechat.mp.extra.pojo.MsgPo;
import zhibi.wechat.mp.service.MsgService;

import static zhibi.wechat.mp.extra.context.BaseConfig.REQUEST_PREFIX;

@Controller
@RequestMapping(REQUEST_PREFIX + "msg")
public class WxMpMsgController extends BaseController {

    @Autowired
    private MsgService msgService;

    /**
     * 接收的消息
     *
     * @param msgPo
     * @param page
     * @param model
     * @return
     */
    @RequestMapping("list")
    public String list(MsgPo msgPo, Page page, Model model) {
        Example example = Example.getInstance()
                .addOrder("createTime", ExampleType.OrderType.DESC)
                .addParam("fu.nickname", msgPo.getFromUserName(), ExampleType.Operation.LIKE)
                .addParam("m.msgType", msgPo.getMsgType());
        PageInfo<MsgPo> pageInfo = msgService.selectPoByExample(example, page);
        setModelAttribute(model, pageInfo);
        return VIEW_PREFIX + "msg/list";
    }

}
